package cn.echo.ecc.service.impl;

import cn.echo.ecc.constants.RedisConstants;
import cn.echo.ecc.service.ICommonService;
import cn.echo.ecc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CommonServiceImpl implements ICommonService {

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public String createToken(String courseIds) {
        Long loginId = 4L;
        String key = String.format(RedisConstants.COURSE_ORDER_KEY, courseIds, loginId);
        String token = StrUtils.getComplexRandomString(8);
        redisTemplate.opsForValue().set(key, token, 300000, TimeUnit.MILLISECONDS);
        return token;
    }
}
